package com.yunfei.shuanlgu.api;
import com.google.gson.Gson;
import com.yunfei.shuanlgu.result.ResultModel;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * @program: app-shuanglu-servlet
 * @description:
 * @author: zhengyunfei
 * @create: 2019-08-08 14:28
 **/
/**
 * Servlet implementation class HelloServlet
 */
@WebServlet("/ShuangLuServlet")
public class ShuangLuServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShuangLuServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 使用 GBK 设置中文正常显示
        response.setCharacterEncoding("GBK");
        response.getWriter().write("菜鸟教程2：http://www.runoob.com");
        response.getWriter().write(request.getParameter("type"));
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("application/json; charset=UTF-8");
        response.addHeader("Access-Control-Allow-Origin", "*");
        System.out.println("进来了吗？？？？？？？？？？？？？？？？？？？？？？？？？、");
        String type=request.getParameter("type");//环境信息
        String token=request.getParameter("token");//token
        String reserveId=request.getParameter("reserveId");//预约编号
        String fileName=request.getParameter("fileName");//双录视频名称
        String oper=request.getParameter("oper");//接口名称
        Gson gson=new Gson();
        ShuangLuVideoUtil shuangLuVideoUtil=new ShuangLuVideoUtil();
        ResultModel resultModel=new ResultModel();
        if("add".equals(oper)){
            resultModel=shuangLuVideoUtil.add(type,reserveId,fileName);
        }
        if("update".equals(oper)){
            resultModel=shuangLuVideoUtil.update(type,reserveId,fileName);
        }
        if("get".equals(oper)){
            UserInfoApiUtil userInfoApiUtil=new UserInfoApiUtil();
            resultModel=userInfoApiUtil.getUserInfo(type,token);
        }
        PrintWriter pw = response.getWriter();
        pw.write(gson.toJson(resultModel));
        pw.close();
        pw = null;
    }

}